package pluginInterfaces.setup;

import java.util.Enumeration;
import java.util.Vector;

import pluginInterfaces.IMetric;
import pluginInterfaces.IPluginMetric;
import pluginInterfaces.defaultImpl.BaselineRandomClassificationMetric;
import utils.weka.core.Option;
import utils.weka.core.OptionHandler;
import utils.weka.core.Utils;


public class MetricSetup implements IMetric, OptionHandler {
	

	private String name = "";
	private IPluginMetric metric;

	
	public MetricSetup() {
		this.metric = new BaselineRandomClassificationMetric();
	}


	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * 
	 */
	public String getName(){
		return this.name;
	}
		

	public Enumeration listOptions(){
		Vector newVector = new Vector();
		newVector.addElement(new Option("Name","N",0,"-N"));
		newVector.addElement(new Option("Metric","M",0,"-M"));
		return newVector.elements();
	}
	
    public String[] getOptions() {
        String [] options = new String [4];
        int itr = 0;
        
        options[itr++] = "-N";
        options[itr++] = "" + this.name;
        
        options[itr++] = "-M";
        options[itr++] = "" + this.metric.getClass().getName();

        while (itr < options.length) {
          options[itr++] = "";
        }
        return options;
    }
	
	public void setOptions(String[] options) throws Exception {
        String blendStr = Utils.getOption('N', options);
        this.name = blendStr;
		
        String tmpStr     = Utils.getOption('M', options);
        String [] tmpOptions = Utils.splitOptions(tmpStr);
        if (tmpOptions.length != 0) {
          tmpStr        = tmpOptions[0];
          tmpOptions[0] = "";
          this.setMetric((IPluginMetric) Utils.forName(IPluginMetric.class, tmpStr, tmpOptions));
        }
        
        Utils.checkForRemainingOptions(options);
    }

	
	@Override
	public String toString()
	{
		return this.name;
	}

	@Override
	public IPluginMetric getMetric() {
		return this.metric;
	}

	@Override
	public void setMetric(IPluginMetric metric) {
		this.metric = metric;
	}

}
